package com.sc.nft.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.dto.DaoSchoolMaterialArticleSaveAdminDTO;
import com.sc.nft.entity.dto.DaoSchoolMaterialPageAdminDTO;
import com.sc.nft.entity.vo.DaoSchoolMaterialArticlePageAdminVO;
import com.sc.nft.service.DaoSchoolMaterialService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 素材表(DaoSchoolMaterial)表控制层
 *
 * @author makejava
 * @since 2023-03-13 16:22:11
 */

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("admin/daoSchoolMaterial")
@Api(tags = "素材")
public class DaoSchoolMaterialController {

    /**
     * 服务对象
     */
    private final DaoSchoolMaterialService daoSchoolMaterialService;

    @ApiOperation(value = "列表", notes = "列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/pageAdmin", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<DaoSchoolMaterialArticlePageAdminVO> pageAdmin(@RequestBody DaoSchoolMaterialPageAdminDTO pageAdminDTO) {
        Page<DaoSchoolMaterialArticlePageAdminVO> daoSchoolMaterialArticlePageAdminVOPage = daoSchoolMaterialService.pageAdmin(pageAdminDTO);
        return PageResult.success(daoSchoolMaterialArticlePageAdminVOPage);
    }

    @ApiOperation(value = "删除素材", notes = "删除素材", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/deleteById", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result deleteById(@RequestBody @Validated IdRequest idRequest) {
        daoSchoolMaterialService.deleteById(idRequest.getId());
        return Result.success();
    }

    @ApiOperation(value = "新增素材", notes = "新增素材", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/saveAdmin", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result saveAdmin(@RequestBody @Validated DaoSchoolMaterialArticleSaveAdminDTO daoSchoolMaterialArticleSaveAdminDTO) {
        daoSchoolMaterialService.saveAdmin(daoSchoolMaterialArticleSaveAdminDTO);
        return Result.success();
    }
}
